using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using OfficeOpenXml;
using ThresholdAssistant.Dapper.Extensions;
using ThresholdAssistant.Redis;
using ThresholdAssistant.WebAPI.Models;
using System;

namespace ThresholdAssistant.WebAPI
{
    /// <summary>
    /// 应用程序入口
    /// </summary>
    static class Program
    {
        /// <summary>
        /// 程序主函数
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            // 设置许可证上下文
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            CreateHostBuilder(args).Run();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static IHost CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .UseWindowsService()
            //.UseContentRoot(AppContext.BaseDirectory)
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .UseCsRedis(connectionNames: HardCodeConstant.CsRedisConfigName)
            .UseColumnMap("ThresholdAssistant.WebAPI.Models")
            .ConfigureAppConfiguration((context, config) =>
            {
                //NLogUtil.Info($"【阈值助手API】当前系统环境：{EnvConstant.GetEnv()}");
                //NLogUtil.Info($"【阈值助手API】当前项目名称：{EnvConstant.GetProject()}");
            })
            .ConfigureWebHostDefaults(builder =>
            {
                builder
                .UseStartup<Startup>()
                .UseContentRoot(AppContext.BaseDirectory);
                //.UseUrls(BootstrapJson.Configuration.GetValue("Host") ?? "http://*:8081");
            }).Build();
    }
}